package k.dao;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.stereotype.Component;

@Component
public class DemoDao {
	
	@Autowired
	private NamedParameterJdbcTemplate jdbcTemplate;

	public int insert(String str){
		final String sql = "insert into test values(null,:name)";
		KeyHolder keyholder = new GeneratedKeyHolder();
		Map<String,String> paramMap = new HashMap<String,String>();
		paramMap.put("name", str);
		jdbcTemplate.update(sql,new MapSqlParameterSource(paramMap),keyholder);
		return keyholder.getKey().intValue();
	}
	
}
